﻿<UserControl x:Class="SandcastleBuilder.WPF.UserControls.ResourceItemEditorControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:shfbConceptual="clr-namespace:SandcastleBuilder.Utils.ConceptualContent;assembly=SandcastleBuilder.Utils"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="750" MinWidth="100">
  <UserControl.BindingGroup>
    <BindingGroup />
  </UserControl.BindingGroup>
  <UserControl.CommandBindings>
    <CommandBinding Command="ApplicationCommands.Help" Executed="cmdHelp_Executed" />
    <CommandBinding Command="ApplicationCommands.Undo" CanExecute="cmdUndo_CanExecute"
      Executed="cmdUndo_Executed" />
  </UserControl.CommandBindings>
  <UserControl.Resources>
    <BitmapImage x:Key="About" UriSource="../Resources/About.png" />
    <BitmapImage x:Key="Undo" UriSource="../Resources/Undo.png" />

    <Style TargetType="{x:Type Image}" x:Key="toolbarImageStyle">
      <Style.Triggers>
        <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type Button}, AncestorLevel=1}, Path=IsEnabled}" Value="False">
          <Setter Property="Opacity" Value="0.50" />
        </DataTrigger>
      </Style.Triggers>
    </Style>
  </UserControl.Resources>

  <Grid Background="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}">
    <Grid.ColumnDefinitions>
      <ColumnDefinition MinWidth="150" />
      <ColumnDefinition Width="Auto"/>
      <ColumnDefinition MinWidth="250" Width="2*"/>
    </Grid.ColumnDefinitions>
    <Grid Grid.Column="0">
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition />
      </Grid.RowDefinitions>
      <Grid Grid.Row="0">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto" />
          <ColumnDefinition />
          <ColumnDefinition Width="Auto"/>
          <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <Label Content="_Find" VerticalAlignment="Center" Target="{Binding ElementName=txtFindID}" />
        <TextBox Grid.Column="1" Name="txtFindID" VerticalAlignment="Center" Margin="3,0"
          KeyUp="txtFindID_KeyUp" TextChanged="txtFindID_TextChanged" IsReadOnlyCaretVisible="True" />
        <Button Grid.Column="2" Name="btnGo" Content="_Go" ToolTip="Find the next occurrence" Padding="3"
          Margin="0,0,3,0" Click="btnGo_Click" />
        <Button Grid.Column="3" Name="btnHelp" ToolTip="View help for this editor (F1)" Command="ApplicationCommands.Help">
          <Image Source="{StaticResource About}" />
        </Button>
      </Grid>
      <CheckBox Grid.Row="1" Name="chkLimitToOverridden" Content="_Limit to overridden items" Margin="3"
        Click="chkLimitToOverridden_Click" />
      <ListBox Grid.Row="2" Name="lbResourceItems" Margin="3">
        <ListBox.ItemContainerStyle>
          <Style TargetType="{x:Type ListBoxItem}">
            <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
          </Style>
        </ListBox.ItemContainerStyle>
        <ListBox.Resources>
          <DataTemplate DataType="{x:Type shfbConceptual:ResourceItem}">
            <TextBlock Text="{Binding Id}">
              <TextBlock.Style>
                <Style TargetType="{x:Type TextBlock}">
                  <Style.Triggers>
                    <DataTrigger Binding="{Binding IsOverridden}" Value="True">
                        <Setter Property="Background" Value="LightBlue" />
                        <Setter Property="Foreground" Value="Black" />
                    </DataTrigger>
                  </Style.Triggers>
                </Style>
              </TextBlock.Style>
            </TextBlock>
          </DataTemplate>
        </ListBox.Resources>
      </ListBox>
    </Grid>
    <GridSplitter Grid.Column="1" Width="3" VerticalAlignment="Stretch" HorizontalAlignment="Center" ShowsPreview="False" Background="LightGray" />
    <Grid Grid.Column="2"  Background="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}"
      DataContext="{Binding ElementName=lbResourceItems, Path=SelectedItem}">
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition />
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition />
      </Grid.RowDefinitions>
      <Label Grid.Row="0" Grid.Column="0" Content="Item ID" HorizontalAlignment="Right" />
      <TextBox Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" Name="txtID" Margin="3,3" Width="250"
        Text="{Binding Path=Id, Mode=OneWay}" IsReadOnly="True" IsReadOnlyCaretVisible="True" Background="LightGray" />
      <Label Grid.Row="1" Grid.Column="0" Content="Source File" HorizontalAlignment="Right" />
      <TextBox Grid.Row="1" Grid.Column="1" HorizontalAlignment="Stretch" Name="txtSourceFile" Margin="3,3"
        Text="{Binding Path=SourceFile, Mode=OneWay}" IsReadOnly="True" IsReadOnlyCaretVisible="True" Background="LightGray" />
      <Label Grid.Row="2" Grid.Column="0" Content="Item _Content" HorizontalAlignment="Left"
        Target="{Binding ElementName=txtItemContent}" />
      <Button Grid.Row="2" Grid.Column="1" Name="btnUndo" ToolTip="Undo changes to this item (Ctrl+Z)"
        Command="ApplicationCommands.Undo" HorizontalAlignment="Left" Margin="3">
        <Image Source="{StaticResource Undo}" Height="16" Width="16" />
      </Button>
      <TextBox Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Name="txtValue" Margin="3,0"
        Text="{Binding Value, Mode=TwoWay}" AcceptsReturn="True" HorizontalScrollBarVisibility="Visible"
        VerticalScrollBarVisibility="Visible" FontFamily="Courier New" />
    </Grid>
  </Grid>
</UserControl>
